#include "TestBuffer.h"
#include "../src/estrategiaRecurso/Buffer.h"

TestBuffer::TestBuffer() {


}

TestBuffer::~TestBuffer() {

}

void TestBuffer::run() {
	this->testSimple();
	this->testSustitucionSimple();
	this->testComplejo();
	this->testOverflowYreemplazo();
}

void TestBuffer::testSimple() {

	Buffer buffer(100);

	Bytes bytes1("Hola");
	Bytes bytes2(",");
	Bytes bytes3("Mundo!");

	buffer.escribir(bytes1,0);
	buffer.escribir(bytes2,4);
	buffer.escribir(bytes3,5);

	Bytes aux = buffer.leer(0,11);
	assert(aux.toString() == "Hola,Mundo!","Test Simple");

	buffer.imprimirContenido();
}

void TestBuffer::testSustitucionSimple() {

	Buffer buffer(100);

	Bytes bytes1("hola");
	Bytes bytes2("como");

	buffer.escribir(bytes1,4);

	Bytes aux = buffer.leer(4,4);

	assert(aux.toString() == "hola", "Test Sustisucion Simple 1");

	buffer.imprimirContenido();

	buffer.escribir(bytes2,4);

	aux = buffer.leer(4,4);

	assert(aux.toString() == "como", "Test Sustisucion Simple 2");

	buffer.imprimirContenido();
}

void TestBuffer::testComplejo() {

	Buffer buffer(100);

	Bytes bytes1("hola");
	Bytes bytes2("chau");
	Bytes bytes3("llamando");
	Bytes bytes4("buffereando");

	buffer.escribir(bytes1,0); /* (0)hola */
	buffer.escribir(bytes2,3); /* (0)holc (4)hau */

	Bytes aux = buffer.leer(0,7);

	assert(aux.toString() == "holchau","Test Complejo 1");

	buffer.escribir(bytes3,12); /* (0)holc (4)hau  (12)llamando*/
	buffer.escribir(bytes4,6); /* (0)holc (4)ha (6)buffer (12)eandondo*/

	aux = buffer.leer(0,20);

	assert(aux.toString() == "holchabuffereandondo","Test Complejo 2");

	buffer.imprimirContenido();
}

void TestBuffer::testOverflowYreemplazo() {

	Buffer buffer(5);

	Bytes bytes1("hola");
	Bytes bytes2(",");
	Bytes bytes3("Mundo");

	buffer.escribir(bytes1,0);
	buffer.escribir(bytes2,4);

	Bytes aux = buffer.leer(0,5);

	assert(aux.toString() == "hola,","Test Overflow y reemplazo");

	buffer.escribir(bytes3,100); /*Se eliminan los componentes Hola y , */

	aux = buffer.leer(100,5);

	assert(aux.toString() == "Mundo","test Overflow y reemplazo 3");

	buffer.imprimirContenido();
}
